package com.lyncs.ods.modules.txn.service.impl;

import com.lyncs.ods.common.exception.ApiException;
import com.lyncs.ods.constant.LyncsOdsConstant;
import com.lyncs.ods.modules.txn.model.SettlementInfo;
import com.lyncs.ods.modules.txn.mapper.SettlementInfoMapper;
import com.lyncs.ods.modules.txn.service.SettlementInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 结算单总表 服务实现类
 * </p>
 *
 * @author alex
 * @since 2022-03-10
 */
@Service
public class SettlementInfoServiceImpl extends ServiceImpl<SettlementInfoMapper, SettlementInfo> implements SettlementInfoService {

    @Override
    public SettlementInfo getOneById(Long id) {
        SettlementInfo settlementInfo = this.lambdaQuery().eq(SettlementInfo::getId, id).one();
        if (Objects.isNull(settlementInfo) || LyncsOdsConstant.SettlementStatus.DELETED.getKey().equals(settlementInfo.getStatus())) {
            throw new ApiException("结算单不存在或已删除，ID：" + id);
        }
        return settlementInfo;
    }
}
